<template>
  <div>
    <el-row :span="24">
        <el-col :span="8">
            <el-input v-model="likeNameClassify" placeholder="请输入科室编号或者科室类别"></el-input>
        </el-col>
        <el-col :span="8">
            <el-button @click="queryClassify()">查询</el-button>
            <el-button @click="showAddDeptDialog=true">增加科室类别</el-button>
        </el-col>
        <el-col :span="8">
            <p></p>
        </el-col>
        <el-col :span="8">

        </el-col>
    </el-row>
    <el-dialog title="增加科室类别" :visible.sync="showAddDeptDialog" center="">
        <el-form :model="classifyAddForm" :label-position="labelPosition" inline>
            <el-form-item label="科室类别编号:">
                <el-input v-model="classifyAddForm.id" style="width: 222px;" placeholder="请输入部门编号"></el-input>
            </el-form-item>
            <el-form-item label="科室类别名称:">
                <el-input v-model="classifyAddForm.classifyName" style="width: 222px;" placeholder="请输入部门名称"></el-input>
            </el-form-item>
        </el-form>
        <div  slot="footer" class="dialog-footer">
             <el-button type="warning" @click="showAddTypeDialog = false" >取 消</el-button>
             <el-button type="primary" @click="addTypeDialog()">创 建</el-button>
        </div>
    </el-dialog>
      <el-table
        :data="tableData"
        style="width: 100%">
    	<el-table-column
    	  type="selection"
    	  select-on-indeterminate=true
    	  width="160">
    	</el-table-column>
        <el-table-column
          label="CID"
          width="180">
          <template slot-scope="scope">
            {{ scope.row.id }}
          </template>
        </el-table-column>
    	<el-table-column
    	  label="科室类别管理"
    	  width="180">
    	  <template slot-scope="scope">
    	    {{ scope.row.classifyname }}
    	  </template>
    	</el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
               @click="editDept(scope.row)">编辑</el-button>
              <el-dialog title="编辑科室类别" :visible.sync="dialogFormVisible" center>
                <el-form :model="form" :label-position="labelPosition" inline>
                  <el-form-item label="科室类别编号" :label-width="formLabelWidth">
                    <el-input v-model="form.classifydata.id" autocomplete="off" disabled style="width: 222px;"></el-input>
                  </el-form-item>
                  <el-form-item label="科室类别名称" :label-width="formLabelWidth">
                    <el-input v-model="form.classifydata.classifyname" autocomplete="off" style="width: 222px;" placeholder="请输入科室编号"></el-input>
                  </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button type="warning" @click="dialogFormVisible = false" >取 消</el-button>
                  <el-button type="primary" @click="updateDept()">确 定</el-button>
                </div>
              </el-dialog>

           <template>
           <el-popconfirm
             :title="'确定删除'+scope.row.classifyname+'?该类别下的科室也将被删除！'"
             @onConfirm="handleDelete(scope.$index, scope.row)"
           >
             <el-button size="mini" type="danger" slot="reference">删除</el-button>
           </el-popconfirm>
           </template>
          </template>
        </el-table-column>
      </el-table>
  </div>
</template>

<script>
  export default{
    name: 'deptclassify',
    data(){
      return{
        showAddDeptDialog:false,
        dialogFormVisible:false,
        labelPosition:"right",
        formLabelWidth:'120px',
		likeNameClassify:'',
        tableData:[
        ],
        classifyAddForm:{

        },
        form:{
          orginData:{
            deptnum:'',
            deptname:'',
            classifyname:'',
            typename:''
          },
          classifydata:{
            originNum:"",

          },
        }
      }
      },
      methods:{
        onlord1:function(){
            let urlTable="/hisbg/deptclassity";
            let g_table=this.$axios.get(urlTable);
        	g_table.then(res=>{
        		this.tableData=res.data;
        	})
        },
        editDept:function(row){
            this.dialogFormVisible = true;
            this.form.orginData.id=row.id;
            this.form.orginData.classifyname=row.classifyname;
            this.form.classifydata=this.form.orginData;
            this.form.classifydata.originNum=row.deptnum;
        },
        // onlord2:function(){
        //     let urlDeptClassity="/hisbg/deptclassity";
        //     let g_deptclassity=this.$axios.get(urlDeptClassity);
        //     g_deptclassity.then(res=>{
        //       this.form.deptclassity=res.data;
        //     })
        // },
        // onlord3:function(){
        //     let urlDeptType="/hisbg/depttype";
        //     let g_depttype=this.$axios.get(urlDeptType);
        //     g_depttype.then(res=>{
        //     	this.form.depttype=res.data;
        //     })
        // }
        handleDelete:function(index,row){
            let classifyId=row.id;
            let url="/hisbg/delclassify?id="+classifyId;
            let g=this.$axios.get(url);
            let rs;
            g.then(res=>{
              rs=res.data;
              if(rs){
                this.onlord1();
              }else{
                alert("删除失败");
              }
            })
        },
        addDeptDialog:function(){
          this.showAddDeptDialog = false;
          let url="/hisbg/addclassify";
          let g = this.$axios.post(url,this.$qs.stringify(this.classifyAddForm));
          let rs;
          g.then(res=>{
            rs=res.data;
            if(rs){
              this.onlord1();
              this.classifyAddForm={};
            }else{
              alert("增加失败");
            }
          })
        },
		queryClassify:function(){
      if(this.likeNameClassify){
          let url=`/hisbg/queryclassify?classifyname=${this.likeNameClassify}&id=${this.likeNameClassify}`;
          let g=this.$axios.get(url);
          let rs;
          g.then(res=>{
            rs=res.data;
            if(rs&&rs.length>0){
              this.tableData=rs;
            }else{
              alert("查询失败");
            }
          })
      }else{
        // alert("请输入需要查询的科室类别");
        this.onlord1();
      }

		},
		updateDept:function(){
			this.dialogFormVisible = false;
			  let url="/hisbg/updateclassify";
			  let g = this.$axios.post(url,this.$qs.stringify(this.form.classifydata));
			  let rs;
			  g.then(res=>{
			    rs=res.data;
			    if(rs){
			      this.onlord1();
			      this.deptAddForm={};
			    }else{
			      alert("编辑失败");
			    }
			  })
		}
      },
      mounted:function(){
        this.onlord1();
        // this.onlord2();
        // this.onlord3();
      },
    }
</script>

<style>
</style>
